package com.invengo.module_check.ui.fragment.first_check.item;

import androidx.annotation.NonNull;

import com.invengo.library_db.entity.module_check.ShelfBean;
import com.invengo.module_check.ui.fragment.first_check.FirstCheckViewModel;

import me.goldze.mvvmhabit.base.ItemViewModel;
import me.goldze.mvvmhabit.binding.command.BindingCommand;
import me.goldze.mvvmhabit.bus.event.SingleLiveEvent;

public class FirstCheckItemViewModel extends ItemViewModel<FirstCheckViewModel> {
    public SingleLiveEvent<ShelfBean> shelfBean = new SingleLiveEvent<>();
    public SingleLiveEvent<Boolean> isNew = new SingleLiveEvent<>();
    public SingleLiveEvent<Boolean> isblue = new SingleLiveEvent<>();

    public FirstCheckItemViewModel(@NonNull FirstCheckViewModel viewModel, ShelfBean bean, int position) {
        super(viewModel);
        shelfBean.postValue(bean);
        isblue.postValue(position % 4 < 2);
    }

    public int getPosition() {
        return viewModel.getPosition(this) + 1;
    }

    public BindingCommand changeBook = new BindingCommand(() -> {
        viewModel.changeFistBook(this);
    });

    public void updateNewBook(ShelfBean bean) {
        isNew.postValue(shelfBean.getValue().getFirstBookID().equals(bean.getFirstBookID()));
        shelfBean.postValue(bean);
    }
}
